<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    /* await fn()函数会立即执行，但是await fn()后面的代码会放入callback里，即异步 */

    /* 案例一 */
    /*   async function async1() {
      console.log("async1 start");
      await async2();
      //await后面的内容都可以看作是callback里的内容，即异步。
      console.log("async1 end");
    }
    async function async2() {
      console.log("async2");
    }
    console.log("script start");
    async1();
    console.log("script end");
    Promise.resolve().then((res) => {
      console.log("66");
    }); */
    // /* 案例二 */
    // async function async1() {
    //   console.log("async1 start");
    //   await async2();
    //   console.log("async1 end");
    //   await async3();
    //   console.log("async1 end 2");
    // }
    // async function async2() {
    //   console.log("async2");
    // }
    // async function async3() {
    //   console.log("async3");
    // }
    // console.log("script start");
    // async1();
    // console.log("script end");
    // Promise.resolve().then((res) => {
    //   console.log("66");
    // });
    /* 案例三 */
    (async function () {
      console.log("start");
      let a = await 100;
      console.log("a", a);
      const b = await Promise.resolve(200);
      console.log("b", b);
      const c = await Promise.reject(300); //await相当于执行的.then,返回的是失败的promise，所以c不会打印，且会报错
      console.log("c", c);
      console.log("end");
    })();
  </script>
</html>
